package com.yygo.dao.hibernate;

import com.yygo.dao.CityDao;
import com.yygo.model.City;
import com.yygo.model.County;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tiansha on 2015/6/24.
 */
@Repository("cityDao")
public class CityDaoHibernate extends GenericDaoHibernate<City, Long> implements CityDao {
    public CityDaoHibernate() {
        super(City.class);
    }
    public List<County> findByCityName(String cityName) {
        List cities = getSession().createCriteria(City.class).add(Restrictions.eq("name", cityName)).list();
        if (cities.size() == 0) {
            return new ArrayList<>();
        }
        City city = (City)cities.get(0);
        List<County> list = city.getCounties();
        return list;
    }
}
